// 二叉树的所有路径

package Leetcode;

import java.util.ArrayList;
import java.util.List;

class Solution_257 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> result = new ArrayList<>();
        if (root.left == null && root.right == null) {
            result.add("" + root.val);
            return result;
        }
        if (root.left != null) {
            List<String> left = binaryTreePaths(root.left);
            for (String l : left)
                result.add(root.val + "->" + l);
        }

        if (root.right != null) {
            List<String> right = binaryTreePaths(root.right);
            for (String r : right)
                result.add(root.val + "->" + r);
        }

        return result;
    }
}